package com.uenpay.im.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qyx.android.message.type.PacketType;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.QYXUserEntity;
import com.uenpay.im.weight.RoundImageView;

import java.util.ArrayList;

public class SearchResultUserListAdatper extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<QYXUserEntity> list;

	public SearchResultUserListAdatper(Context context,
			ArrayList<QYXUserEntity> _list) {
		mInflater = LayoutInflater.from(context);
		list = _list;
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list == null ? null : list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		UserViewHodler holder = null;
		QYXUserEntity user = list.get(arg0);
		if (arg1 == null) {
			holder = new UserViewHodler();
			arg1 = mInflater.inflate(R.layout.user_list_item_layout, null);
			holder.avatar = (RoundImageView) arg1
					.findViewById(R.id.user_avatar);
			holder.name = (TextView) arg1.findViewById(R.id.user_name);
			holder.user_signature = (TextView) arg1
					.findViewById(R.id.user_signature);
			arg1.setTag(holder);
		} else {
			holder = (UserViewHodler) arg1.getTag();
		}
		holder.avatar.SetUrl(APIConfiguration.getAvatarUrlNormal(user.custid,
				PacketType.PERSONAL));
		holder.name.setText(user.nickname);
		holder.user_signature.setText(user.signature);
		return arg1;
	}

	class UserViewHodler {
		private RoundImageView avatar;
		private TextView name, user_signature;
	}

}
